package SQL.Spring.JdbcTemplate.Module;


import SQL.Spring.JdbcTemplate.DAO.JdbcTemplateCustomerDAO;

import SQL.Spring.SpringJDBC.DAO.CustomerDAO;
import SQL.Spring.SpringJDBC.Entity.Customer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by kz on 2017/5/14.
 */
public class jdbcTemplateApp {
    public static void main( String[] args )
    {
        ApplicationContext context =
                new ClassPathXmlApplicationContext(new String[] {"SpringConfigs/Spring-Module.xml"});

     /*   JdbcTemplateCustomerDAO customerDAO = (JdbcTemplateCustomerDAO) context.getBean("JdbcTemplateCustomerDAO");

        Customer customer1 = customerDAO.findByCustomerId(2);

        if (customer1 == null){
            System.out.println("找不到该对象");
        }else
        System.out.println("找到对象:"+ customer1.asString());

        customer1 = customerDAO.findByCustomerId2(1);

        if (customer1 == null){
            System.out.println("找不到该对象");
        }else
            System.out.println("找到对象:"+ customer1.asString());

         List<Customer> customers = customerDAO.findAll();

         for(Customer c :customers) {
             System.out.println(c.asString());
         }*/

       /* JdbcTemplateCustomerDAO customerDAO = (JdbcTemplateCustomerDAO) context.getBean("JdbcTemplateCustomerDAO");
        Customer customer1 = new Customer(1, "yiibai1",21);
        Customer customer3 = new Customer(2, "yiibai2",22);
        Customer customer2 = new Customer(3, "yiibai3",23);

        List<Customer>customers = new ArrayList<Customer>();
        customers.add(customer1);
        customers.add(customer2);
        customers.add(customer3);

        customerDAO.insertBatch(customers);

        String sql = "UPDATE CUSTOMER SET NAME ='kz2'";
        customerDAO.insertBatchSQL(sql);
*/
        JdbcTemplateCustomerDAO customerDAO = (JdbcTemplateCustomerDAO) context.getBean("JdbcTemplateCustomerDAO");     //通过XML获取实例
        List<Customer>customers =  customerDAO.findAll();

        for(Customer c:customers){
            System.out.println(c.asString());
        }

    }
}
